package com.coda.controller;

import com.coda.entity.LeaseTerm;
import com.coda.result.Result;
import com.coda.service.LeaseTermService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/admin/term")
@RestController
@Api(tags = "租期管理")
public class LeaseTermController {

    @Autowired
    private LeaseTermService leaseTermService;

    /**
     * 保存或跟新租期信息
     */
    @PostMapping("/saveOrUpdate")
    @ApiOperation(value = "保存或跟新租期信息")
    public Result saveOrUpdate(@RequestBody LeaseTerm leaseTerm){
        leaseTermService.saveOrUpdate(leaseTerm);
        return Result.ok();
    }
    /**
     * 查询全部租期信息
     */
    @GetMapping("/list")
    @ApiOperation(value = "查询全部租期列表")
    public Result<List<LeaseTerm>> list(){
        List<LeaseTerm> leaseTerms = leaseTermService.getAllLeaseTerm();
        return Result.ok(leaseTerms);
    }
    /**
     * 根据id删除租期
     */
    @DeleteMapping("/deleteById")
    @ApiOperation("根据id删除租期")
    public Result deleteById(Long id){
        leaseTermService.deleteById(id);
        return Result.ok();
    }
}
